package com.ismartv.sale.dao;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class ConnectionManager {
	public static Connection getConnection() throws DaoException {
		Connection conn = null;
		try {
			Context ctx = new InitialContext();
			DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/mysql");
			conn = ds.getConnection();
		} catch (NamingException e) {
			throw new DaoException("can not find datasource", e);
		} catch (SQLException e) {
			throw new DaoException("can not get database connection", e);
		}
		return conn;
	}
}
